package com.example.SpringBootDemo.controller;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

@RestController
@RequestMapping("/user")
public class LoginController {
    @RequestMapping("/login")
    public boolean login(String userName, String passWord, HttpSession session) {
        if(userName.equals("admin") && passWord.equals("admin")) {
            session.setAttribute("userName",userName);
            return true;
        }else {
            return false;
        }
    }
    @RequestMapping("/getLoginUser")
    public String getLoginUser(HttpSession session) {
        String userName = null;
        if(session != null) {
            userName = (String) session.getAttribute("userName");
        }
        System.out.println(userName);
        return userName;
    }
}
